package com.acwing.partition20;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/1/16 19:31
 */
public class AC1945奶牛棒球_二分 {

    private static final int N = 1010;
    private static int[] nums = new int[N];
    private static int n = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        for (int i = 0; i < n; i++) nums[i] = Integer.parseInt(reader.readLine());
        writer.write(resolve() + "\n");
        writer.flush();
    }

    private static int resolve() {
        int answer = 0;
        Arrays.sort(nums, 0, n);
        for (int i = 0; i < n - 2; i++) {
            for (int j = i + 1; j < n - 1; j++) {
                int gap = nums[j] - nums[i];
                //向右二分查找最后一个小于等于2*gap的点
                int left2 = j + 1, right2 = n - 1;
                while (left2 < right2) {
                    int mid = (left2 + right2 + 1) >> 1, dis = nums[mid] - nums[j];
                    if (dis > 2 * gap) right2 = mid - 1;
                    else left2 = mid;
                }
                //向右二分查找第一个大于等于gap的点
                int left1 = j + 1, right1 = n - 1;
                while (left1 < right1) {
                    int mid = (left1 + right1) >> 1, dis = nums[mid] - nums[j];
                    if (dis < gap) left1 = mid + 1;
                    else right1 = mid;
                }
                //如果最小的都大于了gap的两倍或者最大的都小于了gap，就没必要统计
                if (nums[left2] - nums[j] < gap || nums[left1] - nums[j] > 2 * gap) continue;
                answer += left2 - left1 + 1;
            }
        }
        return answer;
    }
}
